import { createRouter, createWebHistory } from 'vue-router';

// 一级路由组件
import Login from '@/views/Login/Login.vue';
import Layout from '@/views/Layout/Layout.vue';

// 二级路由组件
import Home from '@/views/Home/Home.vue';
import Category from '@/views/Category/Category.vue';
import SubCategory from '@/views/SubCategory/SubCategory.vue';
import Detail from '@/views/Detail/Detail.vue';
import CartList from '@/views/CartList/CartList.vue';
import Checkout from '@/views/Checkout/Checkout.vue';
import Pay from '@/views/Pay/Pay.vue';
import PayCallback from '@/views/PayCallback/PayCallback.vue';
import Member from '@/views/Member/Member.vue';

// 三级路由组件
import UserInfo from '@/views/Member/Components/UserInfo/UserInfo.vue';
import UserOrder from '@/views/Member/Components/UserOrder/UserOrder.vue';

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    // 路由与路径映射关系
    routes: [
        {
            path: '/',
            component: Layout,
            children: [
                {
                    path: '',
                    component: Home,
                },
                {
                    path: 'category/:id',
                    component: Category,
                },
                {
                    path: 'category/sub/:id',
                    component: SubCategory,
                },
                {
                    path: 'detail/:id',
                    component: Detail,
                },
                {
                    path: 'cartlist',
                    component: CartList,
                },
                {
                    path: 'checkout',
                    component: Checkout,
                },
                {
                    path: 'pay',
                    component: Pay,
                },
                {
                    path: 'paycallback',
                    component: PayCallback,
                },
                {
                    path: 'member',
                    component: Member,
                    children: [
                        {
                            path: '',
                            component: UserInfo,
                        },
                        {
                            path: 'order',
                            component: UserOrder,
                        }
                    ],
                }
            ]
        },
        { path: '/login', component: Login },
    ],
    scrollBehavior() {
        return { top: 0 };
    },
});

export default router;